# -*- coding: utf-8 -*-
#高级特性----列表生成式，是Python内置的非常简单却强大的可以用来创建list的生成式。

import io
import sys
import os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

list1 = list(range(1,11))
print(list1)

list2 = [ x * x for x in range(1,11)]
print(list2)

list3 = [ x * x for x in range(1,11) if x % 2 == 0]
print(list3)

list4 = [x + y for x in 'ABC' for y in 'abc']
print(list4)

list5 = [d for d in os.listdir(".")]
print(list5)

list6 = [k + ':' + str(v) for k,v in {'a':1,'b':2,'c':3}.items()]
print(list6)

list7 = ['Hello','World','Test']
list7 = [s.lower() for s in list7];
print(list7)



L1 = ['Hello', 'World', 18, 'Apple', None]
L2 = [ s.lower() for s in L1 if isinstance(s,str)]
print(L2)

# 测试:
print(L2)
if L2 == ['hello', 'world', 'apple']:
    print('测试通过!')
else:
    print('测试失败!')